// 将分转为元
export function priceFormat(num) {
	return (num / 100).toFixed(2)
}

export function discount(num1, num2) {
	let percentage = Math.floor((num1 / num2) * 100); // 计算折扣百分比
	let num;

	// 如果个位数为0，则只显示十位数
	if (percentage % 10 === 0) {
		num = Math.floor(percentage / 10);
	} else {
		num = percentage;
	}

	return `${num}折`;
}

export function formatTimestamp(timestamp) {
	// 创建一个新的Date对象，并将其设置为UTC+8
	var date = new Date(timestamp);

	// 设置时区为UTC+8
	var options = {
		timeZone: 'Asia/Shanghai',
		year: 'numeric',
		month: '2-digit',
		day: '2-digit',
		hour: '2-digit',
		minute: '2-digit',
		second: '2-digit'
	};

	// 使用toLocaleString()进行格式化
	var formattedDate = date.toLocaleString('zh-CN', options);

	// 返回格式化的日期和时间
	return formattedDate;
}

// 判断是否管理员
export function isManage() {
	let uid = uniCloud.getCurrentUserInfo().uid;
	let role = uniCloud.getCurrentUserInfo().role;
	if (!uid || !role.includes("manage")) {
		uni.showToast({
			icon: "error",
			title: "没有访问权限",
			duration: 15000,
			complete: () => {
				uni.reLaunch({
			url: "/pages/index/index"
		})
			}
		})
		
	}

}